<?php
  $kefu = $_POST["kefu"];
  $qrcode = $_POST['qrcode'];
  $kfwx = $_POST['kfwx'];
  $ontime = $_POST['ontime'];
  $appid = $_POST['appid'];
  $key = $_POST['key'];
  $link_color = $_POST['link_color'];
  
  include_once("../../untils/conn.php");
  if ($con) {
    mysqli_query($con, "set names utf8");
    $result = $con->query("SELECT * FROM kefu WHERE kefu='" . $kefu . "'");
    if ($result->num_rows == 0) {
      // 数据库中不存在该记录，执行插入操作
      $data = $con->query("INSERT INTO kefu (kefu, qrcode, kfwx, ontime, appid, `key`, `link_color`) VALUES ('" . $kefu . "', '" . $qrcode . "', '" . $kfwx . "', '" . $ontime . "', '" . $appid . "', '" . $key . "', '" . $link_color . "')");
      if ($data > 0) {
        echo "<script>alert('添加信息');window.location.href='../system.php'</script> ";
      } else {
        echo ("<script>alert('添加失败');window.location.replace(document.referrer)</script>");
      }
    } else {
      // 数据库中存在该记录，执行更新操作
      $data = $con->query("UPDATE kefu SET qrcode ='" . $qrcode . "',kfwx='" . $kfwx . "',ontime='" . $ontime . "',appid='" . $appid . "', `key`='" . $key . "', `link_color`='" . $link_color . "' WHERE kefu='" . $kefu . "'");
      if ($data > 0) {
        echo "<script>alert('修改信息成功');window.location.href='../system.php'</script> ";
      } else {
        echo ("<script>alert('修改失败');window.location.replace(document.referrer)</script>");
      }
    }
  }
  $con->close();
?>
